//
//  YWRuntimeOptionsTableViewController.m
//  maintain
//
//  Created by Kyo on 16/7/4.
//  Copyright © 2016年 ewin. All rights reserved.
//

#import "YWRuntimeOptionsTableViewController.h"
#import "YWEquipmentType.h"

@interface YWRuntimeOptionsTableViewController ()

@end

@implementation YWRuntimeOptionsTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)setOptionArray:(NSArray *)optionArray{
    _optionArray = optionArray;
    [self.tableView reloadData];
}

#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section
{
    return [_optionArray count];
}

- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
    
    static NSString* CellIdentifier = @"YWRuntimeOptionsTableViewControllerCellIdentifier";
    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    YWEquipmentFieldOption *option = [_optionArray objectAtIndex:indexPath.row];
    cell.textLabel.text = option.fieldOptionText;
    
    return cell;
}
#pragma mark Table view delegate

- (CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath
{
    return 40;
}
- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
    YWEquipmentFieldOption *option = [_optionArray objectAtIndex:indexPath.row];
    if ([self.delegate respondsToSelector:@selector(selectOption:)]) {
        [_delegate selectOption:option];
    }
}

@end
